package com.huawei.hgip.paintgame.util;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

class DatabaseHelper extends SQLiteOpenHelper{
	
	private final static String DB_NAME = "paintgame.db";
	
	private final static int DB_Ver = 1;
	
	public String TABLE_MENU = "menu";
	
	public String ID = "_id";
	
	public String APP_NAME_STR = "appname";
	
	public String APP_LINK_STR = "applink";
	
	public String APP_ICON_URL_STR = "menu_imgurl";
	
	public String APP_STATES = "appstates";
	
	public String APP_CLICK_TIMES = "appclicktimes";
	
	//建表sql语句
	private final String DB_Create_Menu_Table = "CREATE TABLE IF NOT EXISTS "
		+ TABLE_MENU
		+ " ("
		+ ID
		+ " INTEGER PRIMARY KEY,"
		+ APP_NAME_STR + " VARCHAR,"
		+ APP_LINK_STR + " VARCHAR,"
		+ APP_ICON_URL_STR + " VARCHAR,"
		+ APP_STATES + " INTEGER,"//0 true 1 false
	    + APP_CLICK_TIMES + " INTEGER)";
	
	//初始化表的数据
	private final String init_Db1 = "Insert into " + TABLE_MENU
	+ " values(1, '魔力画', 'com.huawei.hgip.paitgame.PAINT_SEARCH', 'null', 0, 0)";
	
	private final String init_Db2 = "Insert into " + TABLE_MENU
	+ " values(2, '记事本', 'null', 'null', 0, 2)";
	
	private final String init_Db3 = "Insert into " + TABLE_MENU
	+ " values(3, '学写字', 'null', 'null', 0, 3)";

	public DatabaseHelper(Context ctx){
		super(ctx, DB_NAME, null, DB_Ver);
	}
	public void onCreate(SQLiteDatabase db){
		db.execSQL(DB_Create_Menu_Table);
		db.execSQL(init_Db1);
		db.execSQL(init_Db2);
		db.execSQL(init_Db3);
	}
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_MENU);
        onCreate(db);
	}
	
}
